DEVICE  = atmega8
F_CPU   = 16000000
AVRDUDE = avrdude -c usbasp -p $(DEVICE)

CFLAGS  = -Iusbdrv -I.
OBJECTS = main.o

COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)


hex: main.hex

program: backup_rar clean flash

backup_rar:
	backup/Rar.exe a -ag_YYYYMMDD_HHMMSS backup/backup.rar main.c WS2811.h Makefile

flash: main.hex
	$(AVRDUDE) -U flash:w:main.hex:i

clean:
	rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o 

.c.o:
	$(COMPILE) -c $< -o $@

.S.o:
	$(COMPILE) -x assembler-with-cpp -c $< -o $@

.c.s:
	$(COMPILE) -S $< -o $@

main.elf: $(OBJECTS)
	$(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
	rm -f main.hex main.eep.hex
	avr-objcopy -j .text -j .data -O ihex main.elf main.hex
	avr-size main.hex

cpp:
	$(COMPILE) -E main.c
